package redis_db

import (
	"context"
	"fmt"
	"github.com/redis/go-redis/v9"
	log "gobase/logger"
	"time"
)

type RdbConfig struct {
	Addr         string
	Password     string
	DailTimeout  time.Duration
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
	DB           int
	MaxRetries   int
	PoolSize     int
	rDB          *redis.Client
}

func NewRdbConfig(cfg *redis.Options) (IRedis, error) {
	var err error
	//cfg = defaultRdbConfig(cfg)
	cli := redis.NewClient(cfg)

	c, err := cli.Ping(context.Background()).Result()
	if err != nil {
		fmt.Println(c)
		return nil, err
	}
	rdb := &RdbConfig{rDB: cli}
	return rdb, nil
}

func ConnectRedisDB(cfg *redis.Options) (*redis.Client, error) {
	//cfg = defaultRdbConfig(cfg)
	rDB := redis.NewClient(cfg)
	c, err := rDB.Ping(context.Background()).Result()
	if err != nil {
		fmt.Println(c)
		return nil, err
	}
	log.Info("start redis success")
	return rDB, nil
}
